// 单独调用接口

const axios = require("axios");

export const wxGet = async (params: { js_code: string }): Promise<{
  session_key?: string;
  openid?: string;
}> => {
  const config: any = {
    headers: {
      Accept: "application/json",
    },
    method: "get",
  };

  config.url = "https://api.weixin.qq.com/sns/jscode2session";
  config.params = Object.assign({
    appid: "wxea4811d243cd2539",
    secret: "3838924e33ff06e2faafed8cc98feab0",
    grant_type: "authorization_code",
  }, params);

  const response = await axios({
    ...config,
  }).catch((err: any) => err);
  // axios 的状态返回；服务器的状态返回；
  if (response.status === 200) {
    return response?.data || {};
  } else {
    return {};
  }
}

// https://api.weixin.qq.com/sns/jscode2session?appid=wxea4811d243cd2539&secret=3838924e33ff06e2faafed8cc98feab0&js_code=0f3Y3j000uL3vR1xN8400B6nn42Y3j0l&grant_type=authorization_code
